package logic

import (
	"context"
	"srv/model/mysql"

	"srv/internal/svc"
	"srv/shenzhou"

	"github.com/zeromicro/go-zero/core/logx"
)

type DetailGoodsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDetailGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DetailGoodsLogic {
	return &DetailGoodsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DetailGoodsLogic) DetailGoods(in *shenzhou.DetailGoodsRequest) (*shenzhou.GoodsItem, error) {
	g := mysql.Goods{}
	err := g.DetailGoods(int(in.GoodsId))

	if err != nil {
		logx.Error("获取商品详情失败", err)
		return nil, err
	}
	return &shenzhou.GoodsItem{
		GoodsId:    int64(g.ID),
		GoodsTitle: g.GoodsTitle,
		GoodsCover: g.GoodsCover,
		GoodsPrice: float32(g.GoodsPrice),
	}, nil
}
